package com.ctsi.ssdc.controller.front;

import com.ctsi.ssdc.common.R;
import com.ctsi.ssdc.constants.SortedMapConstant;
import com.ctsi.ssdc.entity.SubDistrictTownIndustry;
import com.ctsi.ssdc.service.front.FixedInvestmentService1;
import com.ctsi.ssdc.entity.MinFixedInvestment;
import com.ctsi.ssdc.entity.SubDistrictTownFixedInvestment;
import com.ctsi.ssdc.entity.SubDistrictTownIndustrialInvestment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@RestController
@RequestMapping("/fixedinvestment")
public class FixedInvestmentController1 {
    @Autowired
    FixedInvestmentService1 fixedInvestmentService1;

    /**
     * 分区镇固定资产投资
     * @param year
     * @param month
     * @return
     * List集合（包含MinEconomicIndicators类）
     *      * {   private int month 月份;
     *      *     private double thisMonth 当月;
     *      *     private double monthOnMonth 同比;
     *      *     private double accumulate 累计;}
     */
    @GetMapping("/getAllSubDistrictTownFixedInvestment")
    @CrossOrigin
    public R getAllSubDistrictTownFixedInvestment(@RequestParam int year, @RequestParam int month){
        List<SubDistrictTownFixedInvestment> allInfoList = fixedInvestmentService1.getAllSubDistrictTownFixedInvestment(year, month);
        if(allInfoList == null || allInfoList.isEmpty()) return R.miss("不存在该信息");
        SubDistrictTownFixedInvestment total =  null;
        SubDistrictTownFixedInvestment zhou_zhuang = null; // 周庄
        SubDistrictTownFixedInvestment dian_shan_hu = null; // 淀山湖
        SubDistrictTownFixedInvestment jin_xi = null; // 锦溪
        List<SubDistrictTownFixedInvestment> fiexedList = new ArrayList<>();
        List<SubDistrictTownFixedInvestment> sortedList = new ArrayList<>();
        for (SubDistrictTownFixedInvestment industry : allInfoList) {
            switch (industry.getIndicators()) {
                case "全市总计":
                    total = industry;
                    break;
                case "周庄镇":
                    zhou_zhuang = industry;
                    break;
                case "淀山湖镇":
                    dian_shan_hu = industry;
                    break;
                case "锦溪镇":
                    jin_xi = industry;
                    break;
                default:
                    fiexedList.add(industry);
                    sortedList.add(industry);
            }
        }
        fiexedList.sort(Comparator.comparingInt(a -> SortedMapConstant.get(a.getIndicators())));
        return R.ok().data("total", total).data("zhou_zhuang", zhou_zhuang)
                .data("dian_shan_hu", dian_shan_hu).data("jin_xi", jin_xi)
                .data("fiexedList", fiexedList).data("sortedList", sortedList);
    }
    /**
     * 分区镇工业投资
     * @param year
     * @param month
     * @return
     */

    @GetMapping("/getAllSubDistrictTownIndustrialInvestment")
    @CrossOrigin
    public R getAllSubDistrictTownIndustrialInvestment(@RequestParam int year, @RequestParam int month){
        List<SubDistrictTownIndustrialInvestment> allInfoList = fixedInvestmentService1.getAllSubDistrictTownIndustrialInvestment(year, month);
        if(allInfoList == null || allInfoList.isEmpty()) return R.miss("不存在该信息");
        SubDistrictTownIndustrialInvestment total =  null;
        SubDistrictTownIndustrialInvestment zhou_zhuang = null; // 周庄
        SubDistrictTownIndustrialInvestment dian_shan_hu = null; // 淀山湖
        SubDistrictTownIndustrialInvestment jin_xi = null; // 锦溪
        List<SubDistrictTownIndustrialInvestment> fiexedList = new ArrayList<>();
        List<SubDistrictTownIndustrialInvestment> sortedList = new ArrayList<>();
        for (SubDistrictTownIndustrialInvestment industry : allInfoList) {
            switch (industry.getIndicators()) {
                case "全市总计":
                    total = industry;
                    break;
                case "周庄镇":
                    zhou_zhuang = industry;
                    break;
                case "淀山湖镇":
                    dian_shan_hu = industry;
                    break;
                case "锦溪镇":
                    jin_xi = industry;
                    break;
                default:
                    fiexedList.add(industry);
                    sortedList.add(industry);
            }
        }
        fiexedList.sort(Comparator.comparingInt(a -> SortedMapConstant.get(a.getIndicators())));
        return R.ok().data("total", total).data("zhou_zhuang", zhou_zhuang)
                .data("dian_shan_hu", dian_shan_hu).data("jin_xi", jin_xi)
                .data("fiexedList", fiexedList).data("sortedList", sortedList);
    }

    /**
     * 全社会固定资产投资
     * 工业投资
     * 服务业投资
     * #房地产投资
     * 基础设施项目投资
     * 新兴产业投资
     * 高新技术产业投资
     * 民间投资
     * @param year 年份（int）,indicators 指标 (String)
     * @return
     * List集合（包含MinEconomicIndicators类）
     * {   private int month 月份;
     *     private double thisMonth 当月;
     *     private double monthOnMonth 同比;
     *     private double accumulate 累计;}
     */
    @GetMapping("/getFixedInvestmentByIndicators")
    @CrossOrigin
    public List<MinFixedInvestment> getFixedInvestmentByIndicators(@RequestParam int year, @RequestParam String indicators){
        return fixedInvestmentService1.getFixedInvestmentByIndicators(year,indicators);
    }

    @ApiOperation("基础投资项目数量")
    @GetMapping("/getBasicIndustryInvestmentCount")
    @CrossOrigin
    public Integer getBasicIndustryInvestmentCount(@RequestParam int year, @RequestParam int month){
        return fixedInvestmentService1.getBasicIndustryInvestmentCount(year, month);
    }

    @GetMapping("/getIndustrialInvestmentgs")
    @CrossOrigin
    public int getIndustrialInvestmentgs(@RequestParam int year, @RequestParam int month){
        return fixedInvestmentService1.getIndustrialInvestmentgs(year, month);
    }
    @GetMapping("/getIndustrialInvestmentfdc")
    @CrossOrigin
    public int getIndustrialInvestmentgdc(@RequestParam int year, @RequestParam int month){
        return fixedInvestmentService1.getIndustrialInvestmentfdc(year, month);
    }


}
